package com.sinoglobal.ningxia.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

/**
 * 滑动到底部会触发监听的ScrollView
 * 2017年2月14日10:42:47
 */
public class ScrollBottomScrollView extends ScrollView {
    private ScrollBottomListener scrollBottomListener;
    Boolean flag = true;

    public ScrollBottomScrollView(Context context) {
        super(context);
    }

    public ScrollBottomScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ScrollBottomScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {

        if (t + getHeight() == computeVerticalScrollRange() && flag) {
            flag = false;
            scrollBottomListener.scrollBottom();
        }

        if (t + getHeight() + 10 <= computeVerticalScrollRange()) {
            flag = true;
        }

    }

    public void setScrollBottomListener(ScrollBottomListener scrollBottomListener) {
        this.scrollBottomListener = scrollBottomListener;
    }

    public interface ScrollBottomListener {
        public void scrollBottom();
    }
}
